/**
 * 
 */
package com.massyframework.beanskin.launcher.scanning.maven;

import java.util.Objects;

/**
 * {@link ParentCoordinate}, 父项目工程坐标
 * @author huangkh
 *
 */
class ParentCoordinate extends Coordinate {
	
	private String relativePath; 

	/**
	 * 
	 */
	protected ParentCoordinate(Builder builder) {
		super(builder);
		this.relativePath = Objects.requireNonNull(
				builder.relativePath, "\"relativePath\" cannot be null.");
	}
	
	/**
	 * 关联路径
	 * @return {@link String}
 	 */
	public String getRelativePath() {
		return this.relativePath;
	}
	
	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("ParentCoordinate")
			.append(" [groupId=").append(this.getGroupId()).append(",")
			.append(" artifactId=").append(this.getArtifactId()).append(",")
			.append(" version=").append(this.getVersion()).append(",")
			.append(" relativePath=").append(this.getRelativePath()).append("]");
		return builder.toString();
	}

	/**
     * 创建构建器
     * @return {@link Builder}
     */
    public static Builder newBuilder() {
    	return new Builder();
    }
    
    /**
     * 使用{@code item}创建构建器
     * @param item {@link Coordinate}，坐标
     * @return {@link Builder}
     */
    public static Builder newBuilder(Coordinate item) {
    	return new Builder()
    			.groupId(item.getGroupId())
    			.artifactId(item.getArtifactId())
    			.version(item.getVersion());
    }

	public static class Builder extends Coordinate.Builder {
		
		protected String relativePath = "../pom.xml";
		
		/**
    	 * 设置GroupId
    	 * @param groupId {@link String}
    	 * @return {@link Builder}
    	 */
		@Override
    	public Builder groupId(String groupId) {
    		super.groupId(groupId);
    		return this;
    	}
    	
    	/**
    	 * 设置ArtifactId
    	 * @param artifactId {@link String}
    	 * @return {@link Builder}
    	 */
		@Override
    	public Builder artifactId(String artifactId) {
    		super.artifactId(artifactId);
    		return this;
    	}
    	
    	/**
    	 * 设置版本
    	 * @param version {@link String}
    	 * @return {@link Builder}
    	 */
		@Override
    	public Builder version(String version) {
    		super.version(version);
    		return this;
    	}
		
		/**
		 * 设置相对路径
		 * @param relativePath {@link String}
		 * @return {@link Builder}
		 */
		public Builder relativePath(String relativePath) {
			if (relativePath != null) {
				this.relativePath = relativePath;
			}
			return this;
		}
		
		/**
		 * 创建{@link ParentCoordinate}
		 */
		public ParentCoordinate build() {
			return new ParentCoordinate(this);
		}
	}
}
